{layout name="public/layout" /}
{include file='yxnavbar'}


{include file='sms/sms_header'}
<form class="form-horizontal form" action="" id="form1"  method="post" enctype="multipart/form-data">
    <div class="panel panel-default" role="tabpanel" style="">
        <div class="panel-heading" style="background-color: #478ec8;color: #ffffff;">快捷发送</div>
        <div class="panel-body" style="">
            <div class="form-group">
                <label class="col-sm-1 col-xs-12 control-label">发送手机号</label>
                <div class="col-sm-10 col-xs-12">
                    <textarea rows="10" cols="50" class="form-control" id="mobile_list" >{$mobile_str}</textarea>

                    <span class="help-block">一行一个手机号，重复数据系统会自动删除；</span>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-1 col-xs-12 control-label">短信内容</label>
                <div class="col-sm-10 col-xs-12">
                    <textarea rows="5" cols="50" class="form-control"  id="quick_template"  >{$wait_item['out_template_content']}</textarea>
                    <span class="help-block"><span style="color:#19b5ee;">当前短信内容计费:</span><span id="sms_item_total"></span></span>
                    <span class="help-block" style="color: red;">注意：避免出现违规词，如现金、红包、人民币等</span>
                    <span class="help-block" style="color: blue;">计费说明：短信长度不超过67个字，按照一条短信计费；超过67个字，即为长短信，按照67字/条拆分成多条计费。</span>
                    <span class="help-block" style="color: blue;">字数说明：简体中文、字母、数字、标点符号（不区分全角和半角），都按照一个字计算。</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-1 col-xs-12 control-label">短信使用说明</label>
                <div class="col-sm-10 col-xs-12">
                    <input type="text" class="form-control"  placeholder="请输入短信用途，详细填写便于更快通过审核" id="remark" name="remark"  value="{$wait_item['remark']}" >
                </div>
            </div>
        </div>
    </div>
    <div class="form-group" >
        <div class="col-sm-12">
            <div id="chongfu_div" style="display: none;">
                <span class="help-block">删除：重复<span style="color:#ff0000;" id="chongfu"></span>个；</span>
                <input  name="submit_Confirm" id="submit_Confirm" type="button" value="确认录入（共 {$bufa} 个）并提审" class="btn btn-success col-lg-3" style="width:220px;">
                <input type="hidden" name="order_list_ids" value="{$order_list_ids}" />
                <input type="hidden" name="send_who_confirm" value="{$_P['send_who']}" />
            </div>
            {if $mobile_str}
                {if $wait_item['template_status']==0 || $wait_item['template_status']==2}
                <input type="button" value="重新审核" class="btn btn-primary col-lg-3" id="tryQucik" onclick="tryQucikSms(this)" style="width:120px;">
                {else}
                <input type="button" value="测试短信" onclick="showTestSms()" class="btn btn-success col-lg-3" style="width:120px;margin-right: 20px;">
                <input type="button" value="确认无误，批量发送" onclick="sureQuickSms()" {if $wait_item['confirm_test_sms']==0}disabled{/if} class="btn btn-primary col-lg-4" >
                {/if}

            {else}
                {if $template_id}
                    {if $wait_item['template_status']!=0}
                        <input type="button" value="重新审核" class="btn btn-primary col-lg-3" id="tryQucik" onclick="tryQucikSms(this)" style="width:120px;">
                    {else}
                    <input type="button" value="短信审核中，不可进行操作" class="btn btn-danger col-lg-3"  >
                    {/if}
                {else}
                <input  name="submit" id="btnConfirm" type="button" value="提交审核" class="btn btn-primary col-lg-3" style="width:120px;">
                {/if}
            {/if}

            <input type="hidden" name="__token__" value="{$Request.token}" />
        </div>
    </div>
</form>
<script type="text/javascript">
    var open_yx_sms = "{php echo $open_yx_sms;}";
    $("#btnConfirm").click(function () {
        if (open_yx_sms==0){
            layer.msg(' 【 短信通知未开通 】 开通请到 "群发短信" => "短信配置" 中开启，如有疑问请联系客服！');
            return;
        }
        var quick_template = $("#quick_template").val();
        if (quick_template.length==0){
            layer.msg('请输入短信内容');
            return;
        }
        var remark = $("#remark").val();
        if (remark.length==0){
            layer.msg('请输入短信使用说明');
            return;
        }
        //短信内容审核
        var content = $("#quick_template").val();
        var check_url = "{php echo createWebUrl('sms',array('op'=>'audio_sms_content','themeid'=>$themeid));}";
        $.ajax({
            url:check_url,
            dataType:'json',
            method:'post',
            data:{content:content},
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.msg)
                }else{
                    var filter_word_count = result.data.filter_word_count;
                    var filter_word_log = result.data.filter_word_log;
                    if (filter_word_count>0){
                        layer.msg(filter_word_log);
                        return;
                    }

                }

            },
            fail:function (err) {
                console.log(err)
            }
        });

        var mobile_list = $('#mobile_list').val();
        let postUrl = "{php echo createWebUrl('sms',array('op'=>'check_mobile','themeid'=>$themeid));}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:{mobile_list:mobile_list},
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.msg)
                }else{
                    var mobile_txt = result.data.mobile_txt;
                    var chongfu = result.data.chongfu;
                    var sure = result.data.sure;
                    $('#btnConfirm').hide();
                    $('#chongfu_div').show();
                    $('#chongfu').html(chongfu);
                    $('#submit_Confirm').val("确认录入（共 "+sure +" 个）并提交审核");
                    $('#mobile_list').attr("readonly","readonly");
                    $('#quick_template').attr("readonly","readonly");
                    $("#mobile_list").val(mobile_txt);
                    layer.msg(result.msg);
                }
            },
            fail:function (err) {
                console.log(err)
            }
        })
    });
    //确认提审
    $("#submit_Confirm").click(function () {
        var quick_template = $("#quick_template").val();
        var mobile_list = $('#mobile_list').val();
        var remark = $("#remark").val();
        let postUrl = "{php echo createWebUrl('sms',array('op'=>'quick_sms','themeid'=>$themeid));}";
        var jump_url = "{php echo createWebUrl('sms',array('op'=>'template_list','themeid'=>$themeid));}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:{mobile_list:mobile_list,quick_template:quick_template,remark:remark},
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.msg)
                }else{
                    layer.msg(result.msg)
                    window.location.href = jump_url;
                }
            },
            fail:function (err) {
                console.log(err)
            }
        })
    });
    //监听输入短信内容
    $("#quick_template").bind('input propertychange',function () {
        var length = $("#quick_template").val().length;
        var sms_item_total = Math.ceil(length/67);
        var sms_item_amount = sms_item_total/10;
        var tmp_msg = '当前短信字数为:'+length+'个字,单次手机号发送费用为:'+sms_item_amount+'元;';
        $("#sms_item_total").html(tmp_msg);
    });
    //展示测试短信
    function showTestSms()
    {
        layer.prompt({title:'请输入手机号'},function(val, index){
            if (val.length!=11){
                layer.msg('手机号格式错误');
            }
            layer.close(index);
            let postUrl = "{php echo createWebUrl('sms',array('op'=>'test_sms_send','themeid'=>$themeid));}";
            $.ajax({
                url:postUrl,
                dataType:'json',
                method:'post',
                data:{mobile:val},
                success:function (e) {
                    let status = e.status;
                    let result = e.result;
                    if (status!=1){
                        layer.msg(result.msg)
                    }else{
                        confirmTestSms();
                    }
                },
                fail:function (err) {
                    console.log(err)
                }
            })
        });
    }
    function confirmTestSms()
    {
        layer.confirm('测试短信模版是否送达(短信送达时间约为1-2分钟,请在2分钟后或收到短信,点击下方按钮)',{
            btn:['已收到','未收到'],
            yes:function () {
                let postUrl = "{php echo createWebUrl('sms',array('op'=>'test_sms_send','themeid'=>$themeid,'acc'=>'sure'));}";
                $.ajax({
                    url:postUrl,
                    dataType:'json',
                    method:'post',
                    data:{},
                    success:function (e) {
                        let status = e.status;
                        let result = e.result;
                        if (status!=1){
                            layer.msg(result.msg)
                        }else{
                            layer.msg(result.msg)
                            setTimeout(function () {
                                window.location.reload();
                            },1500);
                        }
                    },
                    fail:function (err) {
                        console.log(err)
                    }
                })
            },
            btn2:function () {
                layer.msg('请重新输入新的测试手机号，如多次未收到请联系管理员');
            }
        })
    }
    function sureQuickSms() {
        let postUrl = "{php echo createWebUrl('sms',array('op'=>'sure_quick_sms','themeid'=>$themeid));}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:{},
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.msg)
                }else{
                    layer.msg(result.msg)
                    setTimeout(function () {
                        window.location.reload();
                    },1500);
                }
            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
    function tryQucikSms() {
        $("#tryQucik").prop('disabled',true);
        var template_id = "{php echo $template_id;}";
        var quick_template = $("#quick_template").val();
        var mobile_list = $('#mobile_list').val();
        var remark = $("#remark").val();
        let postUrl = "{php echo createWebUrl('sms',array('op'=>'quick_sms_edit','themeid'=>$themeid));}";
        var jump_url = "{php echo createWebUrl('sms',array('op'=>'template_list','themeid'=>$themeid));}";
        $.ajax({
            url:postUrl,
            dataType:'json',
            method:'post',
            data:{mobile_list:mobile_list,quick_template:quick_template,remark:remark,template_id:template_id},
            success:function (e) {
                let status = e.status;
                let result = e.result;
                if (status!=1){
                    layer.msg(result.msg)
                    $("#tryQucik").removeAttr('disabled');
                }else{
                    layer.msg(result.msg)
                    window.location.href = jump_url;
                }
            },
            fail:function (err) {
                console.log(err)
            }
        })
    }
</script>
